<?php

namespace app\stock\controller;

use think\Controller;


class Recycle extends Controller
{
    // 用户模型
    protected $BusinessModel;
    protected $relationSearch = true;

    public function _initialize()
    {
        // 继承父类
        parent::_initialize();
        $this->BusinessModel = model('Business.Business');
    }

    public function index()
    {
        $data = $this->BusinessModel->onlyTrashed()->with('scource')->order('deletetime', 'desc')->select();
        $this->success("","",$data);
    }
    // 删除
    public function del()
    {
        $id = $this->request->param('id', 0, 'trim');
        $data = $this->BusinessModel->onlyTrashed()->find($id);
        if (!$data) {
            $this->error('客户不存在');
        }
        $result =$this->BusinessModel->destroy($id,true);
        if($result===false) {
            $this->error('删除失败');
        }
        $this->success('删除成功');
    }
    // 还原
    public function restore()
    {
        $id = $this->request->param('id', 0, 'trim');
        $data = $this->BusinessModel->onlyTrashed()->find($id);
        if (!$data) {
            $this->error('客户不存在');
        }
        $result =$this->BusinessModel->isUpdate()->save(['id' => $id, 'deletetime' => null]);
        if ($result===false) {
            $this->error('还原失败');
        }
        $this->success('还原成功');
    }
}
